package com.module.prms;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.log4j.Logger;

import base.util.Page;
import base.util.ResolveUnit;

import com.activityClient.client.ActivityThread;
import com.module.prms.manager.RoleManager;
import com.module.prms.vo.PrmsRole;
import com.module.sys.ConstantUnit;
import com.module.sys.LoginSession;
import com.webClient.client.SocketClient;
import com.webClient.service.WebClientService;




public class prmsRoleService {
	static SocketClient sClient = null;
	static WebClientService ss = null;
	static Logger logger = Logger.getLogger(prmsRoleService.class.getName ()) ;	
	
	 public Page list(PrmsRole pr, final Integer start,final Integer limit) throws Exception{
		pr.setOrgid(LoginSession.getOrgids());
	  	Page page = new Page();
	  	page.setStart(start);
      	page.setLimit(limit);
      	RoleManager roleManager=RoleManager.getInstance();
      	Page resultPage = roleManager.list(page,pr);
      	return resultPage;
		}
	 /**
	  * 根据组织id获取角色列表
	  * @param orgid
	  * @return
	  * @throws Exception
	  */
	 public Page getorgrole(String orgid)throws Exception{
		 PrmsRole pr = new PrmsRole();
		 pr.setOrgid(orgid);
		 RoleManager roleManager=RoleManager.getInstance();
		 Page page=roleManager.getorgrole(pr);
		 return page;
	 }
	 public PrmsRole findbyid(String userid)
	 {
	  try {
		 	   PrmsRole obj =new PrmsRole();
		 	   obj.setCroleId(userid);
		 	   RoleManager roleManager=RoleManager.getInstance();
		 	   PrmsRole pr=roleManager.findebyid(obj);
		 	   return pr;
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
	 }
	 
	 public Map save(PrmsRole obj){
	  try {
		  	RoleManager roleManager=RoleManager.getInstance();
		  	boolean isTrue=roleManager.add(obj);
		  	Map<String, Object> statusMap = new HashMap<String, Object>();
			statusMap.put("state", isTrue);
			if (isTrue == true) {
				statusMap.put("msg", "保存成功");
			} else {
				statusMap.put("msg", "保存失败");
			}
			return statusMap;
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
	 } 
	 public Map remove(List<String> idArray) throws Exception{
		 RoleManager roleManager=RoleManager.getInstance();
		 boolean isTrue = roleManager.remove(idArray);
		 Map<String, Object> statusMap = new HashMap<String, Object>();
		 statusMap.put("state", isTrue);
		 if (isTrue == true) {
				statusMap.put("msg", "删除成功");
		 } else {
				statusMap.put("msg", "删除失败");
		 }
		 return statusMap;
	 }
	
	 public PrmsRole findRoleByName(PrmsRole role) throws Exception{
		 PrmsRole bean = new PrmsRole();
		 RoleManager roleManager=RoleManager.getInstance();
		 bean=roleManager.RoleFindByName(role);
 	    return bean;
	 }
	public static void main(String args[])
	{
		prmsRoleService ps = new prmsRoleService();
		try {
			//ps.list(0, 5);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
